<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php if (!session_id()) session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>电子商务售前单</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <link href="demo.css" rel="stylesheet" type="text/css"/>
    <script src="scripts/boot.js" type="text/javascript"></script>
    <style>
    </style>

</head>
<body>
<a href="javascript:history.go(-1)">返回上一步</a>
<input value="<?php echo $_GET['gid'] ?>" class='mini-textbox' id='zpId' style="display: none"/>
<div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%;margin-top: 5px;overflow:auto;" plain="false"
     buttons="#tabsButtons"
>
    <div title="赠品明细">

        <div id="datagrid1" class="mini-datagrid" style="height:230px;width: 100%;"
             url="/goods/querygift" idField="id"
             allowResize="true"
             allowCellEdit="true" allowCellSelect="true" multiSelect="true"
             allowCellValid="true" oncellvalidation="" showPager='false'
        >

            <div property="columns">
                <div field="gitem_id" headerAlign="center">赠品物料编号
                    <input property="editor" class="mini-textbox" style="width:100%;"/>
                </div>

                <div field="goods_name" headerAlign="center">SAP物料名称
                    <input property="editor" class="mini-textbox" style="width:100%;"/>
                </div>

                <div field="goods_model" headerAlign="center">型号
                    <input class="mini-textbox" style="width:100%;"/>
                </div>

                <div field="qty" headerAlign="center">数量
                    <input property="editor" class="mini-textbox" style="width:100%;"/>
                </div>

                <div field="yes_not" headerAlign="center">是否启用
                    <input property="editor" class="mini-combobox" style="width:100%;" data="Genders"/>
                </div>

            </div>
        </div>

    </div>
    <!-- <div title="Tab2" iconCls="" >
        2
    </div> -->
</div>

<div id='editForm1'>
    <br/>
    <a class="mini-button" onclick="onButtonEdit()" enabled="" id='query-bt'>&nbsp;&nbsp;添加赠品&nbsp;&nbsp;</a>
    <a class="mini-button" onclick="save()" enabled="" id='query-bt'>&nbsp;&nbsp;保存&nbsp;&nbsp;</a>
</div>
</body>
<script type="text/javascript">
    mini.parse();
    var grid = mini.get("datagrid1");
    search();
    var Genders = [{id: 'Y', text: 'Y'}, {id: 'N', text: 'N'}];
    grid.on("drawcell", function (e) {
        var record = e.record,
            column = e.column,
            field = e.field,
            value = e.value;

        //格式化日期
        if (field == "U_FroTime" || field == 'U_ToTime') {
            if (mini.isDate(value)) e.cellHtml = mini.formatDate(value, "yyyy-MM-dd");

        }


    });

    function search() {

        var id = mini.get('zpId').getValue();
        grid.load({'rid': id});
    }

    function onButtonEdit(e) {
        var btnEdit = this;
        mini.open({
            url: "/sap/goods_select.php",
            title: "选择物料",
            width: 650,
            height: 380,
            ondestroy: function (action) {
                //if (action == "close") return false;
                if (action == "ok") {
                    var iframe = this.getIFrameEl();
                    var data = iframe.contentWindow.GetData();
                    data.gitem_id = data.code;
                    data.goods_name = data.name;
                    data.goods_model = data.color;
                    data = mini.clone(data);    //必须
                    if (data) {
                        grid.addRow(data, 0);

                    }
                }

            }
        });
    }

    function save() {
        var data = grid.getChanges()[0];
        if (data == null) {
            mini.alert('无更新数据');
            return;
        }
        data.gtime_id = mini.get('zpId').getValue();
        if (data.gtime_id == '') {
            mini.alert('出错了,请返回上一步重新操作');
            return;
        }

        var json = mini.encode(data);

        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '保存中...'
        });
        $.ajax({
            url: "/goods/savegift",
            data: {data: json},
            type: "post",
            dataType: 'json',
            success: function (data) {
                if (data.code > 0) {
                    mini.unmask(document.body);
                    mini.alert('保存成功!');
                    search();
                    return;
                } else {
                    mini.unmask(document.body);
                    mini.alert(data.msg);
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }


    function onValueChanged(e) {

        var item = e.selected;
        if (item) {
            mini.get('cname-show').setValue(item.text);
        }
    }

</script>
</html>